package com.blandware.atleap.webapp.form.news;

import javax.servlet.http.HttpServletRequest;
import com.blandware.atleap.webapp.form.BaseForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;
import java.util.Map;
import java.util.HashMap;

/**
 * @struts.form name="newsItemForm" 
 */
public  class NewsItemForm
    extends    BaseForm
    implements java.io.Serializable
{

    protected String publicationDate;

    protected String expirationDate;

    protected Map annotationMap;

    protected Map bodyMap;

    protected String uri;

    protected Boolean active;

    protected Map titleMap;

    protected Map keywordsMap;

    protected Map descriptionMap;

    protected String id;

    protected String version;

    /** Default empty constructor. */
    public NewsItemForm() {}

    public String getPublicationDate()
    {
        return this.publicationDate;
    }

   /**
    * @struts.validator type="required, customdate"
    * @struts.validator-args arg0resource="news.form.publicationDate"
    */
    public void setPublicationDate(String publicationDate)
    {
        this.publicationDate = publicationDate;
    }

    public String getExpirationDate()
    {
        return this.expirationDate;
    }

   /**
    * @struts.validator type="required, customdate"
    * @struts.validator-args arg0resource="news.form.expirationDate"
    */
    public void setExpirationDate(String expirationDate)
    {
        this.expirationDate = expirationDate;
    }

    public Map getAnnotationMap()
	{
		return this.annotationMap;
	}
    public Object getAnnotation(String key)
	{
		return this.annotationMap != null ? this.annotationMap.get(key) : null;
	}

   /**
    */
    public void setAnnotationMap(Map annotationMap)
	{
		this.annotationMap = annotationMap;
	}
    public void setAnnotation(String key, Object value)
	{
		if ( this.annotationMap == null ) {
			this.annotationMap = new HashMap();
		}
		this.annotationMap.put(key, value);
	}

    public Map getBodyMap()
	{
		return this.bodyMap;
	}
    public Object getBody(String key)
	{
		return this.bodyMap != null ? this.bodyMap.get(key) : null;
	}

   /**
    */
    public void setBodyMap(Map bodyMap)
	{
		this.bodyMap = bodyMap;
	}
    public void setBody(String key, Object value)
	{
		if ( this.bodyMap == null ) {
			this.bodyMap = new HashMap();
		}
		this.bodyMap.put(key, value);
	}

    public String getUri()
    {
        return this.uri;
    }

   /**
    * @struts.validator type="required"
    * @struts.validator type="mask" msgkey="core.commons.errors.pageUri"
    * @struts.validator-args arg0resource="core.page.form.uri"
    * @struts.validator-var name="mask" value="^(\/[a-zA-Z0-9\-_\040]+)+$"
    */
    public void setUri(String uri)
    {
        this.uri = uri;
    }

    public Boolean getActive()
    {
        return this.active;
    }

   /**
    */
    public void setActive(Boolean active)
    {
        this.active = active;
    }

    public Map getTitleMap()
	{
		return this.titleMap;
	}
    public Object getTitle(String key)
	{
		return this.titleMap != null ? this.titleMap.get(key) : null;
	}

   /**
    */
    public void setTitleMap(Map titleMap)
	{
		this.titleMap = titleMap;
	}
    public void setTitle(String key, Object value)
	{
		if ( this.titleMap == null ) {
			this.titleMap = new HashMap();
		}
		this.titleMap.put(key, value);
	}

    public Map getKeywordsMap()
	{
		return this.keywordsMap;
	}
    public Object getKeywords(String key)
	{
		return this.keywordsMap != null ? this.keywordsMap.get(key) : null;
	}

   /**
    */
    public void setKeywordsMap(Map keywordsMap)
	{
		this.keywordsMap = keywordsMap;
	}
    public void setKeywords(String key, Object value)
	{
		if ( this.keywordsMap == null ) {
			this.keywordsMap = new HashMap();
		}
		this.keywordsMap.put(key, value);
	}

    public Map getDescriptionMap()
	{
		return this.descriptionMap;
	}
    public Object getDescription(String key)
	{
		return this.descriptionMap != null ? this.descriptionMap.get(key) : null;
	}

   /**
    */
    public void setDescriptionMap(Map descriptionMap)
	{
		this.descriptionMap = descriptionMap;
	}
    public void setDescription(String key, Object value)
	{
		if ( this.descriptionMap == null ) {
			this.descriptionMap = new HashMap();
		}
		this.descriptionMap.put(key, value);
	}

    public String getId()
    {
        return this.id;
    }

   /**
    */
    public void setId(String id)
    {
        this.id = id;
    }

    public String getVersion()
    {
        return this.version;
    }

   /**
    */
    public void setVersion(String version)
    {
        this.version = version;
    }

    /**
     * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping,
     *                                                javax.servlet.http.HttpServletRequest)
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
        // reset any boolean data types to false

        this.active = Boolean.FALSE;

        // reset all linking properties to null

    }

	protected Map annotationCheckedBoxes = java.util.Collections.synchronizedMap(new HashMap());
	protected Map bodyCheckedBoxes = java.util.Collections.synchronizedMap(new HashMap());

	protected String localesMode = null;

	public Map getAnnotationCheckedBoxes() {
		return annotationCheckedBoxes;
	}

	public void setAnnotationCheckedBoxes(Map annotationCheckedBoxes) {
		this.annotationCheckedBoxes = annotationCheckedBoxes;
	}

	/**
	 * Returns true, if checkbox was checked
	 *
	 * @param key Key to look for. If it is exists in map, <code>Boolean.TRUE</code> will be returned
	 * @return <code>Boolean.TRUE</code> if key exists in map, and <code>Boolean.FALSE</code> otherwise
	 */
	public Object getAnnotationCheckedBox(String key) {
		if ( annotationCheckedBoxes.containsKey(key) ) {
			return Boolean.TRUE;
		} else {
			return Boolean.FALSE;
		}
	}

	/**
	 * Puts key in map
	 *
	 * @param key   Key to associate value with
	 * @param value Value to put for specified key
	 */
	public void setAnnotationCheckedBox(String key, Object value) {
		annotationCheckedBoxes.put(key, value);
	}

	public Map getBodyCheckedBoxes() {
		return bodyCheckedBoxes;
	}

	public void setBodyCheckedBoxes(Map bodyCheckedBoxes) {
		this.bodyCheckedBoxes = bodyCheckedBoxes;
	}

	/**
	 * Returns true, if checkbox was checked
	 *
	 * @param key Key to look for. If it is exists in map, <code>Boolean.TRUE</code> will be returned
	 * @return <code>Boolean.TRUE</code> if key exists in map, and <code>Boolean.FALSE</code> otherwise
	 */
	public Object getBodyCheckedBox(String key) {
		if ( bodyCheckedBoxes.containsKey(key) ) {
			return Boolean.TRUE;
		} else {
			return Boolean.FALSE;
		}
	}

	/**
	 * Puts key in map
	 *
	 * @param key   Key to associate value with
	 * @param value Value to put for specified key
	 */
	public void setBodyCheckedBox(String key, Object value) {
		bodyCheckedBoxes.put(key, value);
	}

    public void setLocalesMode(String mode) {
        localesMode = mode;
    }

    public String getLocalesMode() {
        return localesMode;
    }

    /**
     * Decides whether 'check all checkboxes' checkbox need to be checked or
     * not (for annotation locale checkboxes)
     *
     * @param request processed request
     * @param localesMode locales mode being used
     */
    public void setAllCheckedFlagForAnnotationCheckboxes(HttpServletRequest request, String localesMode) {
        if ("selected".equalsIgnoreCase(localesMode)) {
            Boolean checkAllIsChecked;
            java.util.List locales = (java.util.List) request.getSession().getAttribute(com.blandware.atleap.webapp.util.core.WebappConstants.CONTENT_LOCALES_COLLECTION_KEY);
            checkAllIsChecked = getAnnotationCheckedBoxes().size() == locales.size() ? Boolean.TRUE : Boolean.FALSE;
            request.setAttribute(com.blandware.atleap.webapp.util.core.WebappConstants.SELECT_ALL_LOCALES_CHECKBOX_IS_CHECKED, checkAllIsChecked);
        }
    }

    /**
     * Decides whether 'check all checkboxes' checkbox need to be checked or
     * not (for body locale checkboxes)
     *
     * @param request processed request
     * @param localesMode locales mode being used
     */
    public void setAllCheckedFlagForBodyCheckboxes(HttpServletRequest request, String localesMode) {
        if ("selected".equalsIgnoreCase(localesMode)) {
            Boolean checkAllIsChecked;
            java.util.List locales = (java.util.List) request.getSession().getAttribute(com.blandware.atleap.webapp.util.core.WebappConstants.CONTENT_LOCALES_COLLECTION_KEY);
            checkAllIsChecked = getBodyCheckedBoxes().size() == locales.size() ? Boolean.TRUE : Boolean.FALSE;
            request.setAttribute(com.blandware.atleap.webapp.util.core.WebappConstants.SELECT_ALL_LOCALES_CHECKBOX_IS_CHECKED, checkAllIsChecked);
        }
    }

}
